import axios from "axios";

const http = axios.create({
    /*baseURL: "https://6553-101-71-225-41.ngrok-free.app",*/
    baseURL: "http://172.20.10.9:8080",
    /*baseURL: "https://9841-101-71-227-41.ngrok-free.app",*/
    timeout: 30000,
    // withCredentials: true, // 确保请求时携带 cookie

});

// 请求拦截器，添加 token 到请求头
http.interceptors.request.use(
    (config) => {
        const token = localStorage.getItem("token");
        if (token) {
            config.headers["Authorization"] = `${token}`; // 使用 Bearer 规范
        }
        /*console.log(11,config)*/
        return config;
    },
    (error) => Promise.reject(error)
);

// 响应拦截器
http.interceptors.response.use(
    (response) => response,
    (error) => Promise.reject(error)
);

export default http;
